package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.framework.web.page.TableDataInfoMy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.WebGoods;
import com.laowang.project.system.service.WebGoodsService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 网页端商品Controller
 * 
 * @author laowang
 * @date 2023-10-16
 */
@Api(tags = "网页端商品接口")
@RestController
@RequestMapping("/webGoods")
public class WebGoodsController extends BaseController {
    @Autowired
    private WebGoodsService webGoodsService;


    @ApiOperation(value = "查询网页端商品列表",notes = "")
    @GetMapping("/web/list")
    public TableDataInfoMy weblist(WebGoods webGoods ) {
        startPage();
        List<WebGoods> list = webGoodsService.selectWebGoodsList(webGoods);
        return getDataTableMy(list);
    }

    /**
     * 获取网页端商品详细信息
     */
    @ApiOperation(value = "获取网页端商品详细信息",notes = "")
    @GetMapping(value = "/web/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(webGoodsService.selectWebGoodsById(id));
    }

    /**
     * 查询网页端商品列表
     */
    @ApiOperation(value = "查询网页端商品列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(WebGoods webGoods) {
        startPage();
        List<WebGoods> list = webGoodsService.selectWebGoodsList(webGoods);
        return getDataTable(list);
    }
    
    /**
     * 导出网页端商品列表
     */
    @ApiOperation(value = "导出网页端商品列表",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webGoods:export')")
    @Log(title = "网页端商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WebGoods webGoods) {
        List<WebGoods> list = webGoodsService.selectWebGoodsList(webGoods);
        ExcelUtil<WebGoods> util = new ExcelUtil<WebGoods>(WebGoods.class);
        return util.exportExcel(list, "webGoods");
    }



    /**
     * 新增网页端商品
     */
    @ApiOperation(value = "新增网页端商品",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webGoods:add')")
    @Log(title = "网页端商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebGoods webGoods) {
        return toAjax(webGoodsService.insertWebGoods(webGoods));
    }

    /**
     * 修改网页端商品
     */
    @ApiOperation(value = "修改网页端商品",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webGoods:edit')")
    @Log(title = "网页端商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebGoods webGoods) {
        return toAjax(webGoodsService.updateWebGoods(webGoods));
    }

    /**
     * 删除网页端商品
     */
    @ApiOperation(value = "删除网页端商品",notes = "")
    @PreAuthorize("@ss.hasPermi('system:webGoods:remove')")
    @Log(title = "网页端商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(webGoodsService.deleteWebGoodsByIds(ids));
    }
}
